package com.example.jpa1;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Date;

@SpringBootApplication
@RestController
public class Jpa1Application {
    @Autowired
    PoemWjmRepository poemWjmRepository;

    @GetMapping("/save_data")
    public void saveData() throws IOException, InterruptedException {
        AddPoem.saveData(poemWjmRepository);
    }

    @GetMapping("addPoem")
    public String addPoem(PoemWjm poemWjm){
        poemWjm.setCreateTime(new Date());
        poemWjmRepository.save(poemWjm);
        return "ok";
    }

    @GetMapping("deleteById")
    public String deleteById(long id){
        poemWjmRepository.deleteById(id);
        return "ok";
    }

    @GetMapping("/findByPoetName")
    public Iterable<PoemWjm>
    findByPoetName(String poetName){
        return poemWjmRepository.findByPoetName(poetName);
    }

    @GetMapping("/findByPoemChaodai")
    public Iterable<PoemWjm>
    findByPoemChaodai(String poemChaodai){
        return poemWjmRepository.findByPoemChaodai(poemChaodai);
    }

    @GetMapping("/findByPoemType")
    public Iterable<PoemWjm>
    findByPoemType(String poemType){
        return poemWjmRepository.findByPoemType(poemType);
    }

    @GetMapping("/findByPoemName")
    public Iterable<PoemWjm>
    findByPoemName(String poemName){
        return poemWjmRepository.findByPoemName(poemName);
    }


    @GetMapping("findByPoemContent")
    public Iterable<PoemWjm> findByPoemContent(String poemContent){
        return poemWjmRepository.findByPoemContent(poemContent);
    }

    public static void main(String[] args) {
        SpringApplication.run(Jpa1Application.class, args);
    }

}

